package me.lijf.mqlite.redis.message;

import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Log4j2
@Component
@EnableScheduling
public class MessageTimer {
    @Autowired
    private RedisTemplate<String,Object> redisTemplate;
    @Value("${redis.message.que}")
    private String que;

    @Scheduled(cron = "0/1 * * * * ?")
    public void consume(){
        Long todo=redisTemplate.opsForList().size(que);
        if(todo==0) return;
        Object value = redisTemplate.opsForList().rightPop(que);
        log.info("timer消费了[{}]的消息：{}",que,value);
    }
}
